#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class Solution
{
public:
    int findMaximizedCapital(int k, int w, vector<int> &profits,
                             vector<int> &capital)
    {
        vector<pair<int, int>> projects;
        for (int i = 0; i < capital.size(); i++)
        {
            projects.push_back(make_pair(capital[i], profits[i]));
        }
        sort(projects.begin(), projects.end());

        priority_queue<int, vector<int>, less<int>> profits_pq;
        int i = 0;
        for (int kd = 0; kd < k; kd++)
        {
            for (; i < projects.size(); i++)
            {
                if (projects[i].first <= w)
                {
                    profits_pq.push(projects[i].second);
                }
                else
                {
                    break;
                }
            }
            if (!profits_pq.empty())
            {
                w += profits_pq.top();
                profits_pq.pop();
            }
            else
            {
                break;
            }
        }
        return w;
    }
};

int main()
{
    cout << "Code502" << endl;
    Solution s;
    vector<int> profits = {1, 2, 3};
    vector<int> capital = {0, 1, 2};
    cout << s.findMaximizedCapital(10, 0, profits, capital) << endl;
    return 0;
}